package org.tourism.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.tourism.entity.EmergencyInfo;
import org.tourism.mapper.EmergencyInfoMapper;
import org.tourism.service.EmergencyInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author wuling
 * @since 2024-07-05
 */
@Service
public class EmergencyInfoServiceImpl extends ServiceImpl<EmergencyInfoMapper, EmergencyInfo> implements EmergencyInfoService {
    @Autowired
    private EmergencyInfoMapper emergencyInfoMapper;
    private QueryWrapper<EmergencyInfo> queryWrapper = new QueryWrapper<EmergencyInfo>();
    @Override
    public int insertEmergencyInfo(EmergencyInfo emergencyInfo) {
        return emergencyInfoMapper.insert(emergencyInfo);
    }

    @Override
    public int updateEmergencyInfo(EmergencyInfo emergencyInfo) {
        //emergencyInfo.setId(selectEmergencyInfoIdByEmergencyContent(emergencyInfo.getContent()));
        //emergencyInfoMapper.update()
        return emergencyInfoMapper.updateById(emergencyInfo);
    }

    @Override
    public int deleteEmergencyInfo(int id) {
        return emergencyInfoMapper.deleteById(id);
    }

    @Override
    public int deleteEmergencyInfoByEmergencyContent(String emergencyContent) {
        queryWrapper.eq("content", emergencyContent);
        return emergencyInfoMapper.delete(queryWrapper);
    }

    @Override
    public EmergencyInfo selectEmergencyInfo(int id) {
        return emergencyInfoMapper.selectById(id);
    }

    @Override
    public int selectEmergencyInfoIdByEmergencyContent(String emergencyContent) {
        queryWrapper.eq("content", emergencyContent);
        return emergencyInfoMapper.selectOne(queryWrapper).getId();
    }

    @Override
    public List<EmergencyInfo> selectAllEmergencyInfo() {
        return emergencyInfoMapper.selectList(null);
    }
}
